<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repository escape_repository_Repository */
	$repository =& $this->requestAttributes['repository'];
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $oreObject escape_repository_OreObject */
	$oreObject =& $this->requestAttributes['oreObject'];
	/* @var $aggregation escape_repository_OreAggregation */
	$aggregation =& $this->requestAttributes['aggregation'];
	/* @var $errorMessages array */
	$errorMessages =& $this->requestAttributes['errorMessages'];
	
	$returnUrl = $this->requestAttributes['returnUrl'];
	$signupUrl = $this->requestAttributes['signupUrl'];
		
	if($aggregation !== null)
	{
		$repositoryUi->setTemplateFromAggregation($aggregation);
	}
	
	$templateVariables = array();
	$templateVariables['title'] = 'Log in';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Selection">

<div class="escape_Section">

<?php
	if(count($errorMessages) > 0)
	{
?>
<div>
<?php
		foreach($errorMessages as $errorMessage)
		{
?>
<div class="escape_Error"><?php print $errorMessage; ?></div>
<?php
		}
?>
</div>
<?php
	}
?>

<?php
	if($repository->config['saml']['enabled'])
	{
?>
<div class="escape_SectionTitle">Log in using <?php print htmlspecialchars($repository->config['saml']['label'])?>:</div>

<form method="get" action="/beginSamlLogin">
<input type="hidden" name="return_url" value="<?php print htmlspecialchars($returnUrl); ?>" />

<input type="submit" value="Log in" />

</form>

<br class="escape_Note" />
<?php
	}
?>


<div class="escape_SectionTitle">Log in using your ESCAPE account:</div>

<form method="get" action="login">
<input type="hidden" name="verb" value="beginLocal" />
<input type="hidden" name="return_url" value="<?php print htmlspecialchars($returnUrl); ?>" />

<table class="escape_FormTable">
<tr>
<td>
User ID:
</td>
<td>
<input type="text" name="userid" value="<?php print htmlspecialchars($_REQUEST['userid']); ?>" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" value="" />
</td>
</tr>
</table>
<input type="submit" value="Log in" />

<?php
	$actionLinks = array();
	if($repository->config['signup_enabled'])
	{
		$actionLinks[] = '<a href="' . htmlspecialchars($signupUrl) . '">Create an ESCAPE account</a>';
	}
	if($repository->config['password_reset_enabled'])
	{
		$actionLinks[] = '<a href="/sendPasswordResetEmail" target="_blank">Forgot your password?</a>';
	}

	if(count($actionLinks) > 0)
	{
?>
<p class="escape_Note">
<?php print implode(' | ', $actionLinks); ?>
</p>
<?php
	}
	else 
	{
?>
<br class="escape_Note" />
<?php
	}
?>

</form>

<?php
	if($repository->config['openidauthn_enabled'] && $repository->config['signup_enabled'])
	{
?>
<br class="escape_Note" />

<div class="escape_SectionTitle">Log in using OpenID:</div>

<?php
	$repositoryUi->displayOpenIdLoginForm('ProcessOpenIdLogin', 'Login', array('return_url' => $returnUrl));
?>
<?php
	}
?>

</div>

</div>

<?php $this->displayFooter(); ?>
